package com.lagou.rpc.consumer.controller;

import com.lagou.rpc.api.IUserService;
import com.lagou.rpc.consumer.anno.RpcRemoteService;
import com.lagou.rpc.pojo.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @author 伍文彬
 * @date 2021-04-25 09:15
 **/
@RestController
public class UserController {

    @RpcRemoteService
    private IUserService userService;

    @GetMapping("/test")
    public Object test() {
        return LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
    }


    @GetMapping("/user")
    public Object getUserById(Integer id) {
        User user = userService.getById(id);
        return "来自服务器：[" + user.getFromPort() + "]的返回结果：" + user;
    }
}
